import 'package:flutter/material.dart';
import 'package:flutter_pickers/pickers.dart';
import 'package:flutter_pickers/style/default_style.dart';
import 'package:flutter_pickers/style/picker_style.dart';
import 'package:ty_smart_watch/bean/setting_item_bean.dart';
import 'package:ty_smart_watch/common/images_url.dart';
import 'package:ty_smart_watch/utils/Log.dart';

class SettingList extends StatelessWidget {
  SettingList({super.key});

  final items = [
    SettingItemBean(SETTING_ITEM_ICON_PERMISSION, "权限管理", Icons.arrow_forward_ios),
    SettingItemBean(SETTING_ITEM_ICON_LANGUAGE, "语言选择", Icons.arrow_forward_ios),
    SettingItemBean(SETTING_ITEM_ICON_THEME, "主题切换", Icons.arrow_forward_ios),
    SettingItemBean(SETTING_ITEM_ICON_ABOUT_US, "关于我们", Icons.arrow_forward_ios),
    SettingItemBean(SETTING_ITEM_ICON_VERSION, "软件版本", Icons.arrow_forward_ios),
  ];

  @override
  Widget build(BuildContext context) {
    return Container(
      // height: 210,
      margin: const EdgeInsets.fromLTRB(10, 10, 10, 0),
      // color: Colors.cyan,
      child: ListView.builder(
        shrinkWrap: true,
        physics: const NeverScrollableScrollPhysics(),
        scrollDirection: Axis.vertical,
        // 设置滚动方向为水平
        itemCount: 5,
        itemBuilder: (context, index) {
          final item = items[index];
          return GestureDetector(
              onTap: () {
                // 在此处添加你希望执行的点击事件处理逻辑
                _clickItem(context, index);
              },
              child: Container(
                decoration: const BoxDecoration(
                    border: Border(bottom: BorderSide(width: 1, color: Color(0xffe5e5e5)))),
                child: ListTile(
                  leading: Image.asset(
                    item.icon,
                    width: 32,
                    height: 32,
                  ),
                  title: Text(item.title),
                  trailing: Icon(
                    // Icons.arrow_forward_ios,
                    item.trailing,
                    size: 14,
                    color: Colors.grey,
                  ),
                  contentPadding: const EdgeInsets.symmetric(vertical: 4),
                ),
              ));
        },
      ),
    );
  }

  _clickItem(BuildContext context, int id) {
    print('Clicked on $id');
    switch (id) {
      case 0:
        break;
      case 1:
        _changeLanguageDialog(context);
        break;
    }
  }

  _changeLanguageDialog(BuildContext context) {
    List<String> languageList = ["中文", "英文"];
    Pickers.showSinglePicker(
      context,
      data: languageList,
      selectData: languageList[0],
      pickerStyle: LanguagePickerStyle(),
      onConfirm: (p, position) {
        Log.d("语言选择结果:$p >> $position");
        // _controller.updateData(bean.id, position);
      },
    );
  }
}

/// 性别弹窗样式
class LanguagePickerStyle extends PickerStyle {
  LanguagePickerStyle({bool haveRadius = false, String? title}) {
    commitButton = Container(
      alignment: Alignment.center,
      padding: const EdgeInsets.only(left: 12, right: 22),
      child: const Text('确定', style: TextStyle(color: Colors.black, fontSize: 16.0)),
    );
  }
}
